<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>资金管理</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <style type="text/css">
        .info-div {
            font-size: 16px;
            color: #7f7f7f;
            flex: 1;
        }

        #settingsDialog .layui-form-item .layui-input-inline {
            width: 100px!important;
        }
    </style>
    <%@include file="../include/commonFile.jsp" %>
</head>
<body>

<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li class="layui-this"><span class="title f18 ml5 mr5">全部资金</span></li>
                    <li><span class="title f18 ml5 mr5">众筹资金</span></li>
                </ul>
                <div class="member-index-top mt20">
                    <div class="top-left">
                        <div style="flex: 1;">
                            <div class="display-flex">
                                <div class="info-div" style="font-size:20px;display:inline; margin-right: 30px;">
                                    <span>累计资金： </span>
                                    <span><b class="active-red">
                                          <c:if test="${orderTotal > 0}">
                                              <fmt:formatNumber pattern="#,###.##" value="${orderTotal}"/>
                                          </c:if>
                                          <c:if test="${orderTotal == 0.0}">${orderTotal}</c:if>
                                          </b>
                                   </span>
                                </div>
                                <c:if test="${!isChildAccount}">
                                    <div class="info-div" style="font-size:20px;display:inline; margin-right: 30px;">
                                        <span>短信剩余数量： </span>
                                        <span style="font-size: 24px; font-family: '微软雅黑';">
                                                ${packageCount.totalNum < packageCount.useNum ? 0 : packageCount.totalNum - packageCount.useNum}</span>&nbsp;条
                                        <a href="javascript:recharge()" target="_self" class="layui-btn layui-btn-danger layui-btn-sm ml10">充值</a>
                                        <a href="javascript:countSettings()" target="_self" class="layui-btn layui-btn-danger layui-btn-sm ml10">配置</a>
                                    </div>
                                    <c:if test="${packageCount.useNum - packageCount.totalNum > 0}">
                                        <div class="info-div" style="font-size:20px;display:inline; margin-right: 30px;">
                                            <span>短信超出数量： </span>
                                            <span style="font-size: 24px; font-family: '微软雅黑';">
                                                    ${packageCount.useNum - packageCount.totalNum}
                                            </span>&nbsp;条
                                        </div>
                                    </c:if>
                                    <div class="info-div" style="font-size:20px;display:inline; margin-right: 30px;">
                                        <span>短信收费状态： </span>
                                        <span>${packageCount.isOpen == 1 ? '已开启' : ''}
                                          ${empty packageCount.id || packageCount.isOpen == 2 ? '已关闭' : ''}
                                    </span>
                                    </div>
                                    <c:if test="${packageCount.isOpen == 1}">
                                        <div class="info-div" style="font-size:20px;display:inline">
                                            <span>短信允许超出状态： </span>
                                            <span>${packageCount.isAllowExcess == 1 ? '已开启' : ''}
                                         ${packageCount.isAllowExcess == 2 ? '已关闭' : ''}
                                    </span>
                                        </div>
                                    </c:if>
                                </c:if>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <form class="layui-form" action="${ctx}/moneyManagement/allMoneyList.do" id="myForm"
                              method="post">
                            <input type="hidden" name="pageNo" id="pageNo"/>
                            <input type="hidden" name="memberId" id="memberId" value="${memberId}"/>

                            <div class="f-search-bar">
                                <div class="search-container">
                                    <ul class="search-form-content">
                                        <li class="form-item"><label class="search-form-lable"></label>
                                            <div class="check-btn-inner">
                                                <a href="javascript:void(0);"
                                                   onclick="setOpType($(this),0,'#myForm')" ${empty stype || stype == 0 ? 'class="active"' : ''}>收益明细</a>
                                                <c:if test="${isBand}">
                                                    <a href="javascript:void(0);"
                                                       onclick="setOpType($(this),1,'#myForm')" ${stype == 1 ? 'class="active"' : ''}>提现明细</a>
                                                </c:if>
                                                <input type="hidden" name="stype" value="${stype}"/>
                                            </div>
                                        </li>
                                    </ul>
                                    <c:if test="${stype == 0}">
                                        <ul class="search-form-content">
                                            <li class="form-item-inline"><label class="search-form-lable">订单名称</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="title" class="layui-input"
                                                           value="${orderForm.title}" placeholder="请输入查询订单名称">
                                                </div>
                                            </li>
                                            <li class="form-item-inline"><label class="search-form-lable"
                                                                                style="margin-left: 14px;">下单者</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="memberName" class="layui-input"
                                                           value="${input.memberName}" placeholder="请输入查询订单下单者">
                                                </div>
                                            </li>
                                            <li class="form-item-inline">
                                                <div class="sub-btns">
                                                    <a class="layui-btn layui-btn-danger" href="javascript:submitClk()">确定</a>
                                                    <a class="layui-btn layui-btn-normal" href="javascript:resetFunction('#myForm')">重置</a>
                                                </div>
                                            </li>
                                        </ul>
                                        <ul class="search-form-content">
                                            <li class="form-item"><label class="search-form-lable">订单类型</label>
                                                <div class="check-btn-inner">
                                                    <a id="all" href="javascript:void(0);"
                                                       onclick="setTimeType($(this),'','#myForm')" ${empty orderForm.type ? 'class="active"' : ''}>全部</a>
                                                    <c:forEach var="map" items="${orderTypes}">
                                                        <a href="javascript:void(0);"
                                                           onclick="setTimeType($(this),'${map.key}','#myForm')" ${orderForm.type == map.key ? 'class="active"' : ''}>${map.value}</a>
                                                    </c:forEach>
                                                    <input type="hidden" name="type" value="${orderForm.type}"/>
                                                </div>
                                            </li>
                                        </ul>
                                        <ul class="search-form-content">
                                            <li class="form-item"><label class="search-form-lable">下单时间</label>
                                                <div class="check-btn-inner" id="timeType">
                                                    <a href="javascript:void(0);"
                                                       onclick="setTimeType($(this),0,'#myForm')" ${empty input.timeType || input.timeType == 0 ? 'class="active"' : ''}>全部</a>
                                                    <a href="javascript:void(0);"
                                                       onclick="setTimeType($(this),4,'#myForm')" ${input.timeType == 4 ? 'class="active"' : ''}>昨天</a>
                                                    <a href="javascript:void(0);"
                                                       onclick="setTimeType($(this),1,'#myForm')" ${input.timeType == 1 ? 'class="active"' : ''}>今天</a>
                                                    <a href="javascript:void(0);"
                                                       onclick="setTimeType($(this),2,'#myForm')" ${input.timeType == 2 ? 'class="active"' : ''}>本周内</a>
                                                    <a href="javascript:void(0);"
                                                       onclick="setTimeType($(this),3,'#myForm')" ${input.timeType == 3 ? 'class="active"' : ''}>本月内</a>
                                                    <input type="hidden" name="timeType" value="${input.timeType}"/>
                                                </div>
                                                <div class="layui-inline">
                                                    <div class="layui-input-inline">
                                                        <input class="layui-input" type="text" name="createStart"
                                                               value="${input.createStart}" placeholder="开始日">
                                                    </div>
                                                    -
                                                    <div class="layui-input-inline">
                                                        <input class="layui-input" type="text" name="createEnd"
                                                               value="${input.createEnd}" placeholder="截止日">
                                                    </div>
                                                </div>
                                            </li>
                                        </ul>
                                    </c:if>
                                    <c:if test="${stype == 1}">
                                        <ul class="search-form-content">
                                            <div class="l" style="width: 50%">
                                                <li class="f16">提现总金额
                                                    <span class="red">
											<c:if test="${withdrawalTotal > 0}">
                                                <fmt:formatNumber pattern="#,###.##" value="${withdrawalTotal}"/>
                                            </c:if>
											<c:if test="${withdrawalTotal == 0.0}">
                                                ${withdrawalTotal}
                                            </c:if>
										</span> 元（包含已扣除0.6%的微信商户提现手续费）
                                                </li>
                                            </div>

                                            <p class="cl"></p>
                                        </ul>
                                    </c:if>
                                </div>
                            </div>
                        </form>
                        <div class="my-act-list-content">
                            <div class="cl">
                                <c:if test="${stype == 0}">
                                    <table class="layui-table">
                                        <colgroup>
                                            <col>
                                            <col>
                                            <col>
                                            <col width="150px">
                                            <col width="150px">
                                            <col width="150px">
                                            <col width="150px">
                                            <col width="150px">
                                            <col width="110px">
                                        </colgroup>
                                        <thead>
                                        <tr>
                                            <th>订单名称</th>
                                            <th>下单者</th>
                                            <th>商户</th>
                                            <th>订单类型</th>
                                            <th>金额</th>
                                            <th>订单状态</th>
                                            <th>支付方式</th>
                                            <th>下单时间</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <c:if test="${page.totalCount == 0}">
                                            <tr>
                                                <td colspan="9">
                                                    <div class="f16 tc">还没有提现明细记录</div>
                                                </td>
                                            </tr>
                                        </c:if>
                                        <c:forEach var="orderForm" items="${orderForms}">
                                            <tr>
                                                <td title="${orderForm.title}"
                                                    onclick="openDialogNoButton('订单详情','${ctx}/order/order/orderInfo.do?id=${orderForm.id}','450px','570px')">
                                                    <div class="member-name ellipsis-1 blue"
                                                         style="cursor: pointer">${orderForm.title}</div>
                                                </td>
                                                <td class="table-member"
                                                    onclick="openDialogShow('用户名片','${ctx}/system/member/memberView.do?id=${orderForm.memberId}','400px','470px')">
                                                    <div class="member-cell">
                                                        <div class="member-logo common-img">
                                                            <img src="<c:if test="${ orderForm.member.logo!= null}">${orderForm.member.logo}?imageMogr2/auto-orient/crop/126x126</c:if>"
                                                                 alt="" onerror="txz.errImg(this)"
                                                                 onload="txz.imgLoad(this)">
                                                        </div>
                                                        <div class="member-name ellipsis-1">
                                                            <a class="blue" title="${orderForm.member.realname}"
                                                               style="cursor: pointer;">${orderForm.member.realname}</a>
                                                        </div>
                                                    </div>
                                                </td>
                                                <td>${orderForm.merchantName}</td>
                                                <td>${orderForm.typeName}</td>
                                                <td>￥${orderForm.payment}</td>
                                                <td>
                                                    <c:choose>
                                                        <c:when test="${orderForm.status == 0}">
                                                            <span>审核中</span>
                                                        </c:when>
                                                        <c:when test="${orderForm.status == 1}">
                                                            <span>待支付</span>
                                                        </c:when>
                                                        <c:when test="${orderForm.status == 2}">
                                                            <span style="color: red;">已支付</span>
                                                        </c:when>
                                                        <c:when test="${orderForm.status == 3}">
                                                            <span>其它</span>
                                                        </c:when>
                                                        <c:when test="${orderForm.status == 4}">
                                                            <span>已退款</span>
                                                        </c:when>
                                                    </c:choose>
                                                </td>
                                                <td>
                                                    <div>
                                                        <c:choose>
                                                            <c:when test="${orderForm.paymentWay == 1}">微信</c:when>
                                                            <c:when test="${orderForm.paymentWay == 0}">支付宝</c:when>
                                                        </c:choose>
                                                    </div>
                                                </td>
                                                <td><fmt:formatDate value="${orderForm.updateDate}"
                                                                    pattern="yyyy-MM-dd HH:mm"/></td>
                                                <td>
                                                    <c:if test="${orderForm.type == 3 || orderForm.type == 7}"><a
                                                            href="javascript:showAuthor('${orderForm.id}')" class="red">查看众筹者</a></c:if>
                                                </td>
                                            </tr>
                                        </c:forEach>
                                        </tbody>
                                    </table>
                                </c:if>

                                <c:if test="${stype == 1}">
                                    <table class="layui-table">
                                        <colgroup>
                                            <col width="240px">
                                            <col width="240px">
                                            <col width="110px">
                                            <col width="110px">
                                            <col width="120px">
                                            <col width="120px">
                                            <col width="140px">
                                            <col width="110px">
                                        </colgroup>
                                        <thead>
                                        <tr>
                                            <th>提现账号</th>
                                            <th>开户行</th>
                                            <th>开户名</th>
                                            <th>提现金额</th>
                                            <th title="提现金额x(微信提现手续费(0.006)+平台提现手续费)">手续费<font style="color: red"
                                                                                               size="5">*</font></th>
                                            <th>支付净额</th>
                                            <th>提现时间</th>
                                            <th>状态</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <c:if test="${page.totalCount == 0}">
                                            <tr>
                                                <td colspan="8">
                                                    <div class="f16 tc">还没有提现记录</div>
                                                </td>
                                            </tr>
                                        </c:if>
                                        <c:forEach var="withdrawal" items="${withdrawals}">
                                            <tr>
                                                <td>${withdrawal.accountNumber}</td>
                                                <td>${withdrawal.openedPlace}</td>
                                                <td>${withdrawal.name}</td>
                                                <td><fmt:formatNumber pattern="0.00" value="${withdrawal.payment}"/>元
                                                </td>
                                                <td><fmt:formatNumber pattern="0.00"
                                                                      value="${withdrawal.serviceFee}"/>元
                                                </td>
                                                <td><fmt:formatNumber pattern="0.00"
                                                                      value="${withdrawal.netAmount}"/>元
                                                </td>
                                                <td><fmt:formatDate value="${withdrawal.createDate}"
                                                                    pattern="yyyy-MM-dd HH:mm"/></td>
                                                <td title="${withdrawal.remarks}">
                                                    <c:if test="${withdrawal.status == 1 or withdrawal.status == 4}">
                                                        <span>处理中</span>
                                                    </c:if>
                                                    <c:if test="${withdrawal.status == 2}">
                                                        <span style="color: green;">已付款</span>
                                                    </c:if>
                                                    <c:if test="${withdrawal.status == 3}">
                                                        <span><a href="javascript:showAuthor1('${withdrawal.remarks}')"
                                                                 class="red">已拒绝</a> </span>
                                                    </c:if>
                                                </td>
                                            </tr>
                                        </c:forEach>
                                        </tbody>
                                    </table>
                                </c:if>
                            </div>
                        </div>
                        <div class="page-content">
                            <c:if test="${page.totalCount > 0}">
                                <div class="l page-totalcount">
								<span class="f14 red">共<b id="totalCount">${page.totalCount}</b>条记录
								</span>
                                </div>
                            </c:if>
                            <div id="page_content" class="page-container"></div>
                            <div class="cl"></div>
                        </div>
                    </div>
                    <div class="layui-tab-item"></div>
                    <div class="layui-tab-item"></div>
                </div>
            </div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>
    <%@include file="../system/member/walletInclude.jsp"%>
    <div id="authorDialog">
        <table class="layui-table" lay-skin="line">
            <tbody>
            <tr>
                <td class="table-member">
                    <div class="member-cell">
                        <div class="member-logo"></div>
                        <div class="member-name ellipsis-1">
                            <a href="javascript:void(0);"></a>
                        </div>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>

    <div id="authorDialog1">
        <table class="layui-table" lay-skin="line">
            <tbody>
            <tr>
                <td class="table-member">
                    <div class="member-cell">
                        <div class="member-name ellipsis-1">

                        </div>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>

<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript">

    var form = null,element = null;
    $(function () {

        txz.initHeader({
            nav: [{
                name: '合作商管理'
            }, {
                name: '${memberName}'
            },
                <c:if test="${isChildAccount}">
                {
                    name: '子账号管理'
                },
                </c:if>
                {
                    name: '资金管理',
                    curr: true
                }],
            btns: [{
                name: '返回',
                icon: 'back',
                href: ${isChildAccount} ? '${ctx}/member/group/childList.do?partnerId=${partnerId}' : '${ctx}/system/member/partnerList.do'
            }]
        });

            layui.use(['element','form'], function () {
            element = layui.element,form = layui.form;
            element.on('tab', function (data) {
                if (data.index == 0) {
                    location.href = "${ctx}/moneyManagement/allMoneyList.do?memberId=${memberId}";
                } else if (data.index == 1) {
                    location.href = "${ctx}/moneyManagement/crowdFundingMoneyList.do?memberId=${memberId}";
                }
            });
             form.render('radio');

        });

        //加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}',
            callback: submitClk,
            form:form
        });

        layui.use(['laydate'], function () {
            var laydate = layui.laydate;
            // 查询发布日期
            var start = {
                elem: 'input[name=createStart]'
            };

            var end = {
                elem: 'input[name=createEnd]'
            };
            laydate.render(start);
            laydate.render(end);
        });

        $("#btnExport").click(function () {
            layer.confirm('确认要导出Excel吗?', {
                icon: 3,
                title: '系统提示'
            }, function (index) {
                var url = "${ctx}/wallet/exportOrder.do";

                //loading层
                var loadIndex = layer.load(1, {
                    shade: [0.1, '#fff'] //0.1透明度的白色背景
                });
                $.post(url, $("#myForm").serialize(), function (res) {
                    top.layer.close(loadIndex);
                    if (res.success) {
                        window.location.href = res.data;
                    } else {
                        util.layerMsgError(res.description)
                    }
                });
                top.layer.close(index);
            });
        });
    })

    function showAuthor(orderId) {
        var setPayIndex = layer.open({
            type: 1,
            area: '400px',
            title: '查看众筹者',
            content: $("#authorDialog"),
            btn: ['关闭'],
            success: function () { // 弹出后回调
                $.get('${ctx}/crowdfund/project/getProjectAuthorByOrder.do', {'orderId': orderId}, function (res) {
                    if (res.success) {
                        var logo = res.data.authorLogo;
                        if (logo) {
                            $("#authorDialog").find(".member-logo").css('background-image', 'url(' + logo + '?imageMogr2/auto-orient/crop/126x126)');
                        } else {
                            $("#authorDialog").find(".member-logo").css('background-image', 'url(${ctx}/image/def_user_logo.png)');
                        }
                        $("#authorDialog").find(".member-name a").text(res.data.authorName);
                    } else {
                        util.layerMsgError("查看众筹者失败");
                    }
                })
            },
            end: function () { // 销毁后回调
                $("#authorDialog").find(".member-logo").css('background-image', '');
                $("#authorDialog").find(".member-name a").text('');
            },
            yes: function () { // 确定按钮
                layer.close(setPayIndex);
            }
        });
    }

    function showAuthor1(remarks) {
        var setPayIndex = layer.open({
            type: 1,
            area: '400px',
            title: '查看备注',
            content: $("#authorDialog1"),
            btn: ['关闭'],
            success: function () { // 弹出后回调
                if (remarks != null && remarks.length > 0) {
                    $("#authorDialog1").find(".member-name").text(remarks);
                } else {
                    util.layerMsgError("暂无备注");
                }
            },
            end: function () { // 销毁后回调
                $("#authorDialog1").find(".member-name").text('');
            },
            yes: function () { // 确定按钮
                layer.close(setPayIndex);
            }
        });
    }

    function setOpType(obj, value, myForm) {
        $(obj).parent(".check-btn-inner").find("a").removeClass("active");
        $(obj).addClass("active");
        $(obj).parent(".check-btn-inner").find("[type=hidden]").val(value);
        $(myForm).submit();
    }

    function submitClk(){
        var paramsArray = $("#myForm").serializeArray();
        var params = new Array();
        $.each(paramsArray, function (i, param) {
            if(param.value != ""){
                params.push(param.value);
            }
        });

        if(params.length > 2) {
            $("#flag").val(true);
        } else if(params.length == 2) {
            $("#flag").val(false);
        }
        $("#myForm").submit();
    }

    /**
     * 短信充值
     */
    function recharge() {
        var index = layer.open({
            type: 1,
            area: '350px',
            title: '短信充值',
            content: $("#rechargeDialog"),
            btn: ['确定', '取消'],
            success: function () {
                $("#rechargeDialog [name=quantity]").val("");
            },
            end: function () {
                $("#rechargeDialog [name=quantity]").val("");
            },
            yes: function () {
                var msg = "";
                var value = $("#rechargeDialog [name=quantity]").val();
                if (value == "") {
                    msg = "短信充值数量不能为空";
                } else if (!util.checkNumber(value)) {
                    msg = "请输入正确的数字";
                } else if (parseInt(value) == 0) {
                    msg = "请输入大于0的数字";
                }
                if (msg != "") {
                    util.layerMsgError(msg);
                    return null;
                }

                var index = layer.load(1);
                $.post("${ctx}/member/packageCount/recharge.do", $("#rechargeDialog form").serializeArray(), function (ret) {
                    layer.close(index);
                    if (ret.success == true) {
                        util.layerMsgSuccess('充值成功', function () {
                            window.location.reload();
                        });
                    } else {
                        util.layerMsgError('充值失败');
                    }
                });
            }
        });
    }

    /**
     * 短信配置
     */
    function countSettings() {
        var index = layer.open({
            type: 1,
            area: '370px',
            title: '短信配置',
            content: $("#settingsDialog"),
            btn: ['提交', '取消'],
            success: function () {
                $("#settingsDialog").find("[name=isOpen][value='${packageCount.isOpen}']").prop('checked', true);
                $("#settingsDialog").find("[name=isAllowExcess][value='${packageCount.isAllowExcess}']").prop('checked', true);
                $("#settingsDialog").find("[name=warnNum]").val('${packageCount.warnNum}');
                $("#settingsDialog").find("[name=excessNum]").val('${packageCount.excessNum}');
                form.render('radio');
            },
            end: function () {
                $("#settingsDialog").find("[name=isOpen]").prop('checked', false);
                $("#settingsDialog").find("[name=isAllowExcess]").prop('checked', false);
                $("#settingsDialog").find("[name=warnNum]").val('');
                $("#settingsDialog").find("[name=excessNum]").val('');
            },
            yes: function () {
                var isOpen = $("#settingsDialog").find("[name=isOpen]:checked").val();
                var isAllowExcess = $("#settingsDialog").find("[name=isAllowExcess]").val();
                var warnNum = $("#settingsDialog").find("[name=warnNum]").val();
                var excessNum = $("#settingsDialog").find("[name=excessNum]").val();
                if (isOpen == undefined || isOpen == "") {
                    util.layerMsgError('请选择开关控制');
                    return null;
                }

                if (isAllowExcess == undefined || isAllowExcess == "") {
                    util.layerMsgError('请选择允许超出开关控制');
                    return null;
                }

                if (warnNum == "") {
                    util.layerMsgError("请输入预警数量");
                    return null;
                } else if (!util.checkNumber(warnNum)) {
                    util.layerMsgError("请输入正确的数字");
                    return null;
                }

                /*if (excessNum == "") {
                    layer.msg("请输入允许超出数量");
                    return null;
                } else if (!util.checkNumber(excessNum)) {
                    layer.msg("请输入正确的数字");
                    return null;
                }*/

                var index = layer.load(1);
                $.post("${ctx}/member/packageCount/saveSettings.do", $("#settingsDialog form").serializeArray(), function (ret) {
                    layer.close(index);
                    if (ret.success == true) {
                        util.layerMsgSuccess("提交成功", function () {
                            window.location.reload();
                        });
                    } else {
                        util.layerMsgError("提交失败")
                    }
                });
            }
        });
    }

</script>
</body>
</html>